/*
 * @Author: your name
 * @Date: 2021-05-31 14:17:57
 * @LastEditTime: 2021-06-07 15:05:53
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \egg-demo\app\schema\goods.js
 */

'use strict';

// const uuidv1 = require('uuid/v1');
// import { v4 as uuidv4 } from 'uuid';

module.exports = app => {
  const { Sequelize } = app;
  const { STRING, BIGINT, DATE, ENUM, Op, UUIDV4, UUID } = Sequelize;
  const uuid = require('uuid').v1();

  return {
    uuid: {
      type: STRING(38),
      allowNull: false,
      primaryKey: true,
      defaultValue: UUIDV4,
    },
    created_at: DATE,
    updated_at: DATE,
    created_use_uuid: {
      type: UUID,
      allowNull: true,
      references: {
        model: 'users',
        key: 'uuid',
      },
      onUpdate: 'cascade',
      onDelete: 'cascade',
    },
    name: {
      type: STRING(128),
      allowNull: false,
      comment: "商品名",
    },
    intro: {
      type: STRING(255),
      allowNull: true,
      comment: "商品介绍",
    },
    price: {
      type: BIGINT,
      defaultValue: 0,
      comment: "商品价格",
    },
    imgs: {
      type: STRING(255),
      allowNull: true,
    },
    goods_id: {
      type: STRING(38),
      allowNull: false,
    },
    goods_status: {
      type: ENUM("empty", "salling", "discount", "new"),
      allowNull: false,
      comment: "商品状态",
    }
  }
}
